package dataCollection;

public class Tree <ContentType> {
  private TreeElement<ContentType> top_;
  
  public Tree() {
    top_ = new TreeElement<ContentType>();
  }
  
  public TreeElement<ContentType> top() {
    return top_;
  }
  
  public ContentType getItem() {
    return top_.getItem();
  }
  
  public void pop() {
    top_ = top_.getParent();
  }
  
  public long size() {
    return top_.getDepth();
  }
  
  public boolean isEmpty() {
    return (top_.getDepth() == 0);
  }
  
  public void pushAndStay(ContentType item) {
    new TreeElement<ContentType>(item, top_);
  }

  public void push(ContentType item) {
    TreeElement<ContentType> new_elem = new TreeElement<ContentType>(item, top_);
    top_ = new_elem;
  }
  
  /**
   * @postcondition: elem must be a node of the tree, 
   *                 anything else is a data corruption
   * @param elem
   */
  public void setTop(TreeElement<ContentType> elem) {
    top_ = elem;
  }

}
